package cn.bsb.controller.backstage;


import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.bsb.pojo.BackendUser;
import cn.bsb.service.backstage.backendUserService;
import cn.bsb.tools.Constants;

@Controller
@RequestMapping(value = "/login")
public class loginController {
	@Autowired
	private backendUserService backendUser;
	
	@RequestMapping("adminLogin")
	public String inLogin() {
		return "backstage/login";
	}
	
	@RequestMapping(value="/ok", method = RequestMethod.POST)
	public String okIndex(String user_code,String password,HttpSession session, Model attr) {
		BackendUser user = backendUser.getOne(user_code, password);
		if(user == null) {
			attr.addAttribute("message", "用户名或密码错误!");
			return "backstage/login";
		}
		session.setAttribute(Constants.admin_SESSION, user);
		return "redirect:/index/inIndex";
	}

	@RequestMapping("logout")
	public String logout(HttpSession session) {
		session.removeAttribute(Constants.admin_SESSION);
		return "backstage/login";
	}
}
